package ogr.ktjy.demo.controller;

import net.sf.jsqlparser.statement.select.SubJoin;


import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.LockedAccountException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lwj
 * @since 2024-03-07
 */
@Controller
@RequestMapping("/demo/sysUser")
public class SysUserController {


    @RequestMapping("/")
    public String getlogin() {
        return "login";
    }

    @RequestMapping("doLogin")
    public String getdoLogin(String usrName, String usrPassword, Model model) {
        UsernamePasswordToken token = new UsernamePasswordToken(usrName, usrPassword);

        Subject subject = SecurityUtils.getSubject();
        subject.login(token);
        try {
            subject.login(token);


        } catch (UnknownAccountException e) {
           model.addAttribute("asg","账号不存在");
        }catch (LockedAccountException e){
            System.out.println("令牌过期");
            model.addAttribute("asg","账号或密码错误");
        }catch (AuthenticationException e){
            System.out.println("令牌错误");
            model.addAttribute("asg","令牌错误");
        }
        model.addAttribute("");
        return "main";
    }
}
